package com.lz.ionicbase.model;

import android.content.Context;
import android.content.pm.PackageInfo;

import java.io.Serializable;

/**
 * Created by wyfei on 2017/3/1.
 */

public class AppInfo implements Serializable {

    private AppInfo() {
    }

    private static AppInfo appInfo;
    private static Context context;
    public static AppInfo getAppInfo(Context context){
        if(appInfo == null|| AppInfo.context != context){
            appInfo = new AppInfo();
            appInfo.init(context);
            AppInfo.context = context;
        }
        return appInfo;
    }

    //版本名称
    public String versionName;
    //版本号
    public int versionCode;
    //设备名称
    public String device_name = android.os.Build.MODEL;;
    //操作系统
    public String os_name = "Android";
    //操作系统版本号
    public String os_version = android.os.Build.VERSION.RELEASE;


    private void init(Context context) {
        PackageInfo packInfo;
        try {
            packInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
            if (packInfo != null) {
                versionName = packInfo.versionName;
                versionCode = packInfo.versionCode;
            }
        } catch (Exception e) {
            e.printStackTrace();
            versionName = "1.0.0";
            versionCode = 0;
        }
    }

}
